


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CeleGraph 2.0.200
// Copyright (C) Yonsm 2005-2009, All Rights Reserved.
#pragma once

#define NO_DSHOW_STRSAFE
#include <DShow.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CeleGraph class
class CeleGraph
{
public:
	CeleGraph(IGraphBuilder* pGraph = NULL);
	~CeleGraph();

public:
	operator IGraphBuilder*()
	{
		return m_pGraph;
	}

	IGraphBuilder* operator =(IGraphBuilder* pGraph)
	{
		if (pGraph)
		{
			pGraph->AddRef();
		}
		if (m_pGraph)
		{
			m_pGraph->Release();
		}
		return m_pGraph = pGraph;
	}

	template<class T> operator T()
	{
		T p = NULL;
		QueryInterface(&p);
		return p;
	}

	template<class T> HRESULT QueryInterface(T** pIF)
	{
		return m_pGraph ? m_pGraph->QueryInterface(__uuidof(T), reinterpret_cast<PVOID*>(pIF)) : E_POINTER;
	}

public:
	SIZE GetSize();
	LONGLONG GetDuration();
	OAFilterState GetState();
	LONGLONG GetPos();
	UINT GetPercent();
	LONG GetVolume();
	BOOL IsFullScreen();

	HRESULT SetVolume(LONG lVolume = 1000);
	HRESULT SetFullScreen(BOOL bFullScreen = OATRUE);
	HRESULT SetVideoWindow(HWND hVideoWnd = NULL);
	HRESULT FitToWindow(HWND hVideoWnd);

	HRESULT Run();
	HRESULT Pause();
	HRESULT Stop();
	HRESULT Seek(LONGLONG llPos = 0);

public:
	HRESULT AddToRot(PDWORD pdwRot = NULL);
	HRESULT RemoveFromRot(DWORD dwRot);
	HRESULT SaveToFile(PCWSTR pwzFileName = L"CeleGraph.grf");
	HRESULT LoadFromFile(PCWSTR pwzFileName = L"CeleGraph.grf");

	HRESULT AddFilter(REFCLSID cID, PCWSTR ptzName = NULL, PVOID* ppIF = NULL, const IID* pID = NULL);
	HRESULT ConnectFilter(IPin* pSrc, IBaseFilter* pDst);
	HRESULT ConnectFilter(IBaseFilter* pSrc, IBaseFilter* pDst);
	HRESULT RenderFilter(IBaseFilter* pFilter);
	HRESULT RemoveFilter(PCWSTR ptzName = NULL, BOOL bRemove = TRUE);
	HRESULT RemoveNextFilters(IBaseFilter* pFilter, PIN_DIRECTION dir);
	HRESULT GetNextFilter(IBaseFilter* pFilter, IBaseFilter** ppNext, PIN_DIRECTION dir = PINDIR_OUTPUT);

	HRESULT FindPinInterface(IBaseFilter* pFilter, REFIID iID, PVOID* ppUnknown);
	HRESULT FindFilterInterface(REFIID iID, PVOID* ppUnknown);
	HRESULT FindInterface(REFIID iID, PVOID* ppUnknown);

	HRESULT RenderFile(PCWSTR pwzFileName, HWND hVideoWnd = NULL);

	static HRESULT SetFile(IBaseFilter* pFilter, PCWSTR pwzFileName);
	static HRESULT LoadFile(IBaseFilter* pFilter, PCWSTR pwzFileName);
	static HRESULT ShowProperty(IBaseFilter* pFilter, HWND hParent = NULL);
	static IBaseFilter* DisplayFilter(IBaseFilter* pFilter);

protected:
	IGraphBuilder* m_pGraph;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
